from flask import Flask,request
import os
import config
from gevent import pywsgi
app = Flask(__name__)

@app.route('/')
def index():
    return '<div style="text-align:center;margin-top:10%;"><h3>WebHookTest is running by pywsgi<h3></div>'

@app.route('/hook/test')
def hook():
    name = request.args.get('name')
    if name in config.commandList :
        command = config.commandList[name]
        status = os.system(command)
        if status == 0 :
            return "<p>执行命令：</p>"+command
        else:
            print(status)
            return "<p>执行命令失败:</p>"+command
    else:
        return "<p>参数有问题！</p>"

if __name__ =='__main__':
    #app.run(host='0.0.0.0',port=config.port)
    server = pywsgi.WSGIServer(('0.0.0.0',config.port),app)
    server.serve_forever()